package com.utils;


import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Locale;

public class Convert
{
  public static int strToInt(String str, int defaultValue)
  {
    int result = defaultValue;
    try
    {
      result = Integer.parseInt(str);
    }
    catch (Exception localException) {}
    return result;
  }
  
  public static long strToLong(String str, long defaultValue)
  {
    long result = defaultValue;
    try
    {
      result = Long.parseLong(str);
    }
    catch (Exception localException) {}
    return result;
  }
  
  public static float strToFloat(String str, float defaultValue)
  {
    float result = defaultValue;
    try
    {
      result = Float.parseFloat(str);
    }
    catch (Exception localException) {}
    return result;
  }
  
  public static double strToDouble(String str, double defaultValue)
  {
    double result = defaultValue;
    try
    {
      result = Double.parseDouble(str);
    }
    catch (Exception localException) {}
    return result;
  }
  
  public static boolean strToBoolean(String str, boolean defaultValue)
  {
    boolean result = defaultValue;
    try
    {
      result = Boolean.parseBoolean(str);
    }
    catch (Exception localException) {}
    return result;
  }
  
  public static java.util.Date strToDate(String str, java.util.Date defaultValue)
  {
    return strToDate(str, "yyyy-MM-dd HH:mm:ss", defaultValue);
  }
  
  public static java.util.Date strToDate(String str, String format, java.util.Date defaultValue)
  {
    java.util.Date result = defaultValue;
    SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.ENGLISH);
    try
    {
      result = formatter.parse(str);
    }
    catch (Exception localException) {}
    return result;
  }
  
  public static String dateToStr(java.util.Date date, String defaultValue)
  {
    return dateToStr(date, "yyyy-MM-dd HH:mm:ss", defaultValue);
  }
  
  public static String dateToStr(java.util.Date date, String format, String defaultValue)
  {
    String result = defaultValue;
    SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.ENGLISH);
    try
    {
      result = formatter.format(date);
    }
    catch (Exception localException) {}
    return result;
  }
  
  public static String strToStr(String str, String defaultValue)
  {
    String result = defaultValue;
    if ((str != null) && (!str.isEmpty())) {
      result = str;
    }
    return result;
  }
  
  public static java.sql.Date dateToSqlDate(java.util.Date date)
  {
    return new java.sql.Date(date.getTime());
  }
  
  public static java.util.Date sqlDateToDate(java.sql.Date date)
  {
    return new java.util.Date(date.getTime());
  }
  
  public static Timestamp dateToSqlTimestamp(java.util.Date date)
  {
    return new Timestamp(date.getTime());
  }
  
  public static java.util.Date qlTimestampToDate(Timestamp date)
  {
    return new java.util.Date(date.getTime());
  }
  
  public static int strtoAsc(String st)
  {
    byte[] gc = st.getBytes();
    int asnum = gc[0];
    return asnum;
  }
  
  public static char intToChar(int backnum)
  {
    char stchar = (char)backnum;
    return stchar;
  }
}
